<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import ReUpload from "@/components/ReUpload/index.vue";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "",
    courseId: null,
    content: "",
    video: "",
    rank: 0,
    fileList: []
  })
});

const ruleFormRef = ref();
const uploadRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

function getUploadRef() {
  return uploadRef.value;
}

defineExpose({ getRef, getUploadRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="标题" prop="title">
      <el-input
        v-model="newFormInline.title"
        clearable
        placeholder="请输入标题"
      />
    </el-form-item>
    <el-form-item label="内容" prop="content">
      <el-input
        v-model="newFormInline.content"
        type="textarea"
        :rows="4"
        clearable
        placeholder="请输入内容"
      />
    </el-form-item>
    <el-form-item label="排序" prop="rank">
      <el-input-number
        v-model="newFormInline.rank"
        :min="0"
        :max="9999"
        controls-position="right"
      />
    </el-form-item>
    <el-form-item label="视频" prop="fileList">
      <ReUpload
        ref="uploadRef"
        v-model:file-list="newFormInline.fileList"
        :limit="1"
        :businessId="newFormInline.id"
        tableName="chapters"
        accept=".mp4, .webm, .ogv/og"
        :file-size="1024 * 1024 * 100"
        :tip="'只能上传一个视频,文件类型只能是视频,文件大小不能超过100M'"
      />
    </el-form-item>
  </el-form>
</template>
